package state;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import button.Button;
import constans.Flag;
import constans.Globals;
import constans.ResourceManager;
import controller.GameController;
import controller.ObjectController;
import engine.Frame;
import engine.Map;

public class GameplayState extends State{
	
	private Frame frame = GameController.frame;
	private Map map = GameController.map;
	private int flag;
	public GameplayState()
	{
		
	}
	
	public void render(GameContainer container, Graphics g) throws SlickException
	{	
		map.render(container, g);
		frame.render(container, g);
	}
	public void update(GameContainer container, int delta) throws SlickException
	{
		Input input = container.getInput();
		
		//anulowanie
		if(input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) action(Flag.CANCEL);
			
		frame.update(container, delta);		
        action(frame.getFlag());
        map.update(container, delta);
	}
	private void action(int f)
	{
		if(f != 0)
			flag = f;
		switch(flag)
		{
			case Flag.BUILD:
				map.build(true, frame.getTowerFlag());	
				frame.setDrawDescribe(true);
				break;
		}		
		if(flag != Flag.BUILD)
		{
			map.build(false, 0);
			frame.deClick(-1);
			frame.setDrawDescribe(map.getDescribe());
				
			
		}
			
	}

}
